#include <iostream>
#include <algorithm>

const int N = 1010;
using namespace std;

int f[N][N];
char a[N], b[N];

int main()
{
    int n, m;
    scanf("%d %s", &n, a + 1);
    scanf("%d %s", &m, b + 1);
    for (int i = 1; i <= n; ++i)
    {
        f[i][0] = i;
    }
    for (int j = 1; j <= m; ++j)
    {
        f[0][j] = j;
    }

    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            f[i][j] = min(f[i - 1][j], f[i][j - 1]) + 1;
            f[i][j] = min(f[i][j], f[i - 1][j - 1] + (a[i] != b[j]));
        }
    }
    printf("%d", f[n][m]);
    return 0;
}